/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ineatconseil.yougo.wicket.ui.admin.panel;

import com.ineatconseil.yougo.wicket.dao.RequestTypesDao;
import com.ineatconseil.yougo.wicket.bo.Type;
import javax.management.monitor.StringMonitorMBean;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.ResourceModel;
import org.apache.wicket.model.StringResourceModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author nicolasger
 */
public class TypeCRUD extends Panel {

	Logger logger = LoggerFactory.getLogger(TypeCRUD.class);

	public TypeCRUD(String id, final Class typeCrudInstance) {
		super(id);

		setOutputMarkupId(true);


		Form form = new Form("formCRUD", new CompoundPropertyModel(new LoadableDetachableModel() {

			@Override
			protected Object load() {
				try {
					return typeCrudInstance.newInstance();
				} catch (InstantiationException ex) {
					logger.error(ex.getMessage(), ex);
					throw new RuntimeException(ex);
				} catch (IllegalAccessException ex) {
					logger.error(ex.getMessage(), ex);
					throw new RuntimeException(ex);
				}
			}
		})) {

			@Override
			protected void onSubmit() {
				Type type = (Type) getModelObject();
				//RequestTypesDao.addNewType(type);
//TODO ajouter
			}
		};

		form.add(new Label("typeIDLabel", "ID"));
		form.add(new Label("id"));
		form.add(new Label("typeNameLabel", "Description"));
		form.add(new TextField("description"));
		form.add(new Button("addOrUpdateButton", new ResourceModel("Ajouter/Modifier")));
		add(form);
	}
}
